/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('savingplan', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model CalculateSavingsPlansRequest {
  commodityCode?: string(name='CommodityCode'),
  cycle?: string(name='Cycle'),
  fromAppCode?: string(name='FromAppCode'),
  fromAppName?: string(name='FromAppName'),
  instance?: [ 
    {
      commodityCode?: string(name='CommodityCode'),
      module?: [ 
        {
          componentCode?: string(name='ComponentCode'),
          property?: [ 
            {
              code?: string(name='Code'),
              value?: string(name='Value'),
            }
          ](name='Property'),
        }
      ](name='Module'),
      quantity?: int32(name='Quantity'),
      specCode?: string(name='SpecCode'),
    }
  ](name='Instance'),
  payMode?: string(name='PayMode'),
  requestId?: string(name='RequestId'),
  specCode?: string(name='SpecCode'),
  spnType?: string(name='SpnType'),
  userId?: string(name='UserId'),
}

model CalculateSavingsPlansResponseBody = {
  code?: string(name='Code'),
  data?: [ 
    {
      commodityCode?: string(name='CommodityCode'),
      currency?: string(name='Currency'),
      cycle?: string(name='Cycle'),
      instanceFamily?: string(name='InstanceFamily'),
      payMode?: string(name='PayMode'),
      poolValue?: float(name='PoolValue'),
      region?: string(name='Region'),
      spnType?: string(name='SpnType'),
      userId?: long(name='UserId'),
    }
  ](name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model CalculateSavingsPlansResponse = {
  headers: map[string]string(name='headers'),
  body: CalculateSavingsPlansResponseBody(name='body'),
}

async function calculateSavingsPlansWithOptions(request: CalculateSavingsPlansRequest, runtime: Util.RuntimeOptions): CalculateSavingsPlansResponse {
  Util.validateModel(request);
  var query = {};
  query['CommodityCode'] = request.commodityCode;
  query['Cycle'] = request.cycle;
  query['FromAppCode'] = request.fromAppCode;
  query['FromAppName'] = request.fromAppName;
  query['PayMode'] = request.payMode;
  query['RequestId'] = request.requestId;
  query['SpecCode'] = request.specCode;
  query['SpnType'] = request.spnType;
  query['UserId'] = request.userId;
  var body : map[string]any= {};
  if (!Util.isUnset(request.instance)) {
    body['Instance'] = request.instance;
  }

  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'CalculateSavingsPlans',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function calculateSavingsPlans(request: CalculateSavingsPlansRequest): CalculateSavingsPlansResponse {
  var runtime = new Util.RuntimeOptions{};
  return calculateSavingsPlansWithOptions(request, runtime);
}

model CheckResourceActionRequest {
  bid?: string(name='Bid'),
  country?: string(name='Country'),
  gmtWakeup?: string(name='GmtWakeup'),
  hid?: long(name='Hid'),
  interrupt?: boolean(name='Interrupt'),
  invoker?: string(name='Invoker'),
  level?: long(name='Level'),
  message?: string(name='Message'),
  pk?: string(name='Pk'),
  prompt?: string(name='Prompt'),
  success?: boolean(name='Success'),
  taskExtraData?: string(name='TaskExtraData'),
  taskIdentifier?: string(name='TaskIdentifier'),
  url?: string(name='Url'),
}

model CheckResourceActionResponseBody = {
  bid?: string(name='Bid'),
  country?: string(name='Country'),
  gmtWakeup?: string(name='GmtWakeup'),
  hid?: long(name='Hid'),
  interrupt?: boolean(name='Interrupt'),
  invoker?: string(name='Invoker'),
  level?: long(name='Level'),
  message?: string(name='Message'),
  pk?: string(name='Pk'),
  prompt?: string(name='Prompt'),
  success?: boolean(name='Success'),
  taskExtraData?: string(name='TaskExtraData'),
  taskIdentifier?: string(name='TaskIdentifier'),
  url?: string(name='Url'),
}

model CheckResourceActionResponse = {
  headers: map[string]string(name='headers'),
  body: CheckResourceActionResponseBody(name='body'),
}

async function checkResourceActionWithOptions(request: CheckResourceActionRequest, runtime: Util.RuntimeOptions): CheckResourceActionResponse {
  Util.validateModel(request);
  var query = {};
  query['Bid'] = request.bid;
  query['Country'] = request.country;
  query['GmtWakeup'] = request.gmtWakeup;
  query['Hid'] = request.hid;
  query['Interrupt'] = request.interrupt;
  query['Invoker'] = request.invoker;
  query['Level'] = request.level;
  query['Message'] = request.message;
  query['Pk'] = request.pk;
  query['Prompt'] = request.prompt;
  query['Success'] = request.success;
  query['TaskExtraData'] = request.taskExtraData;
  query['TaskIdentifier'] = request.taskIdentifier;
  query['Url'] = request.url;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CheckResourceAction',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function checkResourceAction(request: CheckResourceActionRequest): CheckResourceActionResponse {
  var runtime = new Util.RuntimeOptions{};
  return checkResourceActionWithOptions(request, runtime);
}

model CompleteCommodityRequest {
  data?: string(name='data'),
}

model CompleteCommodityResponseBody = {
  code?: string(name='code'),
  data?: string(name='data'),
  errorInfoList?: [ string ](name='errorInfoList'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  success?: boolean(name='success'),
  synchro?: boolean(name='synchro'),
}

model CompleteCommodityResponse = {
  headers: map[string]string(name='headers'),
  body: CompleteCommodityResponseBody(name='body'),
}

async function completeCommodityWithOptions(request: CompleteCommodityRequest, runtime: Util.RuntimeOptions): CompleteCommodityResponse {
  Util.validateModel(request);
  var query = {};
  query['data'] = request.data;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CompleteCommodity',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function completeCommodity(request: CompleteCommodityRequest): CompleteCommodityResponse {
  var runtime = new Util.RuntimeOptions{};
  return completeCommodityWithOptions(request, runtime);
}

model CompleteTradeRequest {
  data?: string(name='data'),
}

model CompleteTradeResponseBody = {
  code?: string(name='code'),
  data?: string(name='data'),
  errorInfoList?: [ string ](name='errorInfoList'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  success?: boolean(name='success'),
  synchro?: boolean(name='synchro'),
}

model CompleteTradeResponse = {
  headers: map[string]string(name='headers'),
  body: CompleteTradeResponseBody(name='body'),
}

async function completeTradeWithOptions(request: CompleteTradeRequest, runtime: Util.RuntimeOptions): CompleteTradeResponse {
  Util.validateModel(request);
  var query = {};
  query['data'] = request.data;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CompleteTrade',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function completeTrade(request: CompleteTradeRequest): CompleteTradeResponse {
  var runtime = new Util.RuntimeOptions{};
  return completeTradeWithOptions(request, runtime);
}

model LogicalDeleteResourceActionRequest {
  bid?: string(name='Bid'),
  country?: string(name='Country'),
  gmtWakeup?: string(name='GmtWakeup'),
  hid?: long(name='Hid'),
  interrupt?: boolean(name='Interrupt'),
  invoker?: string(name='Invoker'),
  message?: string(name='Message'),
  pk?: string(name='Pk'),
  success?: boolean(name='Success'),
  taskExtraData?: string(name='TaskExtraData'),
  taskIdentifier?: string(name='TaskIdentifier'),
}

model LogicalDeleteResourceActionResponseBody = {
  bid?: string(name='Bid'),
  country?: string(name='Country'),
  gmtWakeup?: string(name='GmtWakeup'),
  hid?: long(name='Hid'),
  interrupt?: boolean(name='Interrupt'),
  invoker?: string(name='Invoker'),
  message?: string(name='Message'),
  pk?: string(name='Pk'),
  success?: boolean(name='Success'),
  taskExtraData?: string(name='TaskExtraData'),
  taskIdentifier?: string(name='TaskIdentifier'),
}

model LogicalDeleteResourceActionResponse = {
  headers: map[string]string(name='headers'),
  body: LogicalDeleteResourceActionResponseBody(name='body'),
}

async function logicalDeleteResourceActionWithOptions(request: LogicalDeleteResourceActionRequest, runtime: Util.RuntimeOptions): LogicalDeleteResourceActionResponse {
  Util.validateModel(request);
  var query = {};
  query['Bid'] = request.bid;
  query['Country'] = request.country;
  query['GmtWakeup'] = request.gmtWakeup;
  query['Hid'] = request.hid;
  query['Interrupt'] = request.interrupt;
  query['Invoker'] = request.invoker;
  query['Message'] = request.message;
  query['Pk'] = request.pk;
  query['Success'] = request.success;
  query['TaskExtraData'] = request.taskExtraData;
  query['TaskIdentifier'] = request.taskIdentifier;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'LogicalDeleteResourceAction',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function logicalDeleteResourceAction(request: LogicalDeleteResourceActionRequest): LogicalDeleteResourceActionResponse {
  var runtime = new Util.RuntimeOptions{};
  return logicalDeleteResourceActionWithOptions(request, runtime);
}

model PayOrderCallbackRequest {
  data?: string(name='data'),
}

model PayOrderCallbackResponseBody = {
  code?: string(name='code'),
  data?: string(name='data'),
  errorInfoList?: [ string ](name='errorInfoList'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  success?: boolean(name='success'),
  synchro?: boolean(name='synchro'),
}

model PayOrderCallbackResponse = {
  headers: map[string]string(name='headers'),
  body: PayOrderCallbackResponseBody(name='body'),
}

async function payOrderCallbackWithOptions(request: PayOrderCallbackRequest, runtime: Util.RuntimeOptions): PayOrderCallbackResponse {
  Util.validateModel(request);
  var query = {};
  query['data'] = request.data;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'PayOrderCallback',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function payOrderCallback(request: PayOrderCallbackRequest): PayOrderCallbackResponse {
  var runtime = new Util.RuntimeOptions{};
  return payOrderCallbackWithOptions(request, runtime);
}

model PhysicalDeleteResourceActionRequest {
  bid?: string(name='Bid'),
  country?: string(name='Country'),
  gmtWakeup?: string(name='GmtWakeup'),
  hid?: long(name='Hid'),
  interrupt?: boolean(name='Interrupt'),
  invoker?: string(name='Invoker'),
  message?: string(name='Message'),
  pk?: string(name='Pk'),
  success?: boolean(name='Success'),
  taskExtraData?: string(name='TaskExtraData'),
  taskIdentifier?: string(name='TaskIdentifier'),
}

model PhysicalDeleteResourceActionResponseBody = {
  bid?: string(name='Bid'),
  country?: string(name='Country'),
  gmtWakeup?: string(name='GmtWakeup'),
  hid?: long(name='Hid'),
  interrupt?: boolean(name='Interrupt'),
  invoker?: string(name='Invoker'),
  message?: string(name='Message'),
  pk?: string(name='Pk'),
  success?: boolean(name='Success'),
  taskExtraData?: string(name='TaskExtraData'),
  taskIdentifier?: string(name='TaskIdentifier'),
}

model PhysicalDeleteResourceActionResponse = {
  headers: map[string]string(name='headers'),
  body: PhysicalDeleteResourceActionResponseBody(name='body'),
}

async function physicalDeleteResourceActionWithOptions(request: PhysicalDeleteResourceActionRequest, runtime: Util.RuntimeOptions): PhysicalDeleteResourceActionResponse {
  Util.validateModel(request);
  var query = {};
  query['Bid'] = request.bid;
  query['Country'] = request.country;
  query['GmtWakeup'] = request.gmtWakeup;
  query['Hid'] = request.hid;
  query['Interrupt'] = request.interrupt;
  query['Invoker'] = request.invoker;
  query['Message'] = request.message;
  query['Pk'] = request.pk;
  query['Success'] = request.success;
  query['TaskExtraData'] = request.taskExtraData;
  query['TaskIdentifier'] = request.taskIdentifier;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'PhysicalDeleteResourceAction',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function physicalDeleteResourceAction(request: PhysicalDeleteResourceActionRequest): PhysicalDeleteResourceActionResponse {
  var runtime = new Util.RuntimeOptions{};
  return physicalDeleteResourceActionWithOptions(request, runtime);
}

model ProcessMessageRequest {
  data?: string(name='data'),
}

model ProcessMessageResponseBody = {
  code?: string(name='code'),
  data?: string(name='data'),
  errorInfoList?: [ string ](name='errorInfoList'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  success?: boolean(name='success'),
  synchro?: boolean(name='synchro'),
}

model ProcessMessageResponse = {
  headers: map[string]string(name='headers'),
  body: ProcessMessageResponseBody(name='body'),
}

async function processMessageWithOptions(request: ProcessMessageRequest, runtime: Util.RuntimeOptions): ProcessMessageResponse {
  Util.validateModel(request);
  var query = {};
  query['data'] = request.data;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ProcessMessage',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function processMessage(request: ProcessMessageRequest): ProcessMessageResponse {
  var runtime = new Util.RuntimeOptions{};
  return processMessageWithOptions(request, runtime);
}

model QuerySavingPlanInstanceInnerRequest {
  currentPage?: int32(name='CurrentPage', description='currentPage'),
  endTime?: float(name='EndTime', description='endTime'),
  fromAppCode?: string(name='FromAppCode', description='fromAppCode'),
  fromAppName?: string(name='FromAppName', description='fromAppName'),
  instanceCode?: string(name='InstanceCode', description='instanceCode'),
  instanceFamily?: string(name='InstanceFamily', description='instanceFamily'),
  pageSize?: int32(name='PageSize', description='pageSize'),
  region?: string(name='Region', description='region'),
  requestId?: string(name='RequestId', description='requestId'),
  spnType?: string(name='SpnType', description='spnType'),
  startTime?: float(name='StartTime', description='startTime'),
  userId?: string(name='UserId', description='userId'),
}

model QuerySavingPlanInstanceInnerResponseBody = {
  code?: string(name='Code', description='code'),
  data?: {
    currentPage?: int32(name='CurrentPage', description='currentPage'),
    datas?: [ 
      {
        commodityCode?: string(name='CommodityCode', description='commodityCode'),
        currency?: string(name='Currency', description='currency'),
        cycle?: string(name='Cycle', description='cycle'),
        endTime?: long(name='EndTime', description='endTime'),
        instanceFamily?: string(name='InstanceFamily', description='instanceFamily'),
        payMode?: string(name='PayMode', description='payMode'),
        poolValue?: float(name='PoolValue', description='poolValue'),
        region?: string(name='Region', description='region'),
        site?: string(name='Site', description='site'),
        spnInstanceCode?: string(name='SpnInstanceCode', description='spnInstanceCode'),
        spnInstanceId?: long(name='SpnInstanceId', description='spnInstanceId'),
        spnType?: string(name='SpnType', description='spnType'),
        startTime?: long(name='StartTime', description='startTime'),
        status?: string(name='Status', description='status'),
        userId?: long(name='UserId', description='userId'),
      }
    ](name='Datas', description='datas'),
    pageSize?: int32(name='PageSize', description='pageSize'),
    totalCount?: int32(name='TotalCount', description='totalCount'),
  }(name='Data', description='data'),
  message?: string(name='Message', description='message'),
  requestId?: string(name='RequestId', description='requestId'),
  success?: boolean(name='Success', description='success'),
}

model QuerySavingPlanInstanceInnerResponse = {
  headers: map[string]string(name='headers'),
  body: QuerySavingPlanInstanceInnerResponseBody(name='body'),
}

async function querySavingPlanInstanceInnerWithOptions(request: QuerySavingPlanInstanceInnerRequest, runtime: Util.RuntimeOptions): QuerySavingPlanInstanceInnerResponse {
  Util.validateModel(request);
  var query = {};
  query['CurrentPage'] = request.currentPage;
  query['EndTime'] = request.endTime;
  query['FromAppCode'] = request.fromAppCode;
  query['FromAppName'] = request.fromAppName;
  query['InstanceCode'] = request.instanceCode;
  query['InstanceFamily'] = request.instanceFamily;
  query['PageSize'] = request.pageSize;
  query['Region'] = request.region;
  query['RequestId'] = request.requestId;
  query['SpnType'] = request.spnType;
  query['StartTime'] = request.startTime;
  query['UserId'] = request.userId;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QuerySavingPlanInstanceInner',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function querySavingPlanInstanceInner(request: QuerySavingPlanInstanceInnerRequest): QuerySavingPlanInstanceInnerResponse {
  var runtime = new Util.RuntimeOptions{};
  return querySavingPlanInstanceInnerWithOptions(request, runtime);
}

model VerifyTradeRequest {
  data?: string(name='data'),
}

model VerifyTradeResponseBody = {
  code?: string(name='code'),
  data?: string(name='data'),
  errorInfoList?: [ string ](name='errorInfoList'),
  message?: string(name='message'),
  requestId?: string(name='requestId'),
  success?: boolean(name='success'),
  synchro?: boolean(name='synchro'),
}

model VerifyTradeResponse = {
  headers: map[string]string(name='headers'),
  body: VerifyTradeResponseBody(name='body'),
}

async function verifyTradeWithOptions(request: VerifyTradeRequest, runtime: Util.RuntimeOptions): VerifyTradeResponse {
  Util.validateModel(request);
  var query = {};
  query['data'] = request.data;
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'VerifyTrade',
    version = '2020-07-15',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function verifyTrade(request: VerifyTradeRequest): VerifyTradeResponse {
  var runtime = new Util.RuntimeOptions{};
  return verifyTradeWithOptions(request, runtime);
}

